<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="huoyun" uri="/huoyun"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>选择应标车辆</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/theme/css/main.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/theme/js/calendar/WdatePicker.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/theme/js/jquery-1.6.js"></script>

<style type="text/css">
.selectCar td input.text{
	width: 120px;
}

.tdLabel {
	width: 120px;
	font-size: 12px;
    font-weight: normal;
    text-align: right;
}

.tdValue {
	width: 180px;
	font-size: 12px;
    font-weight: normal;
    text-align: left;
}
</style>

<script type="text/javascript">
	function validate(bid) {
		
		if($("#carDetailID").val() == -1) 
		{
			$("#error_msg").text("请选择车牌号！");
			$("#error_msg").slideToggle("fast");
			return false;
		}
		else if($("#load_time").val() == '')
		{
			$("#error_msg").text("请选择装货时间！");
			$("#error_msg").slideToggle("fast");
			return false;
		}
		else if($("#bid").val() == '')
		{
			$("#error_msg").text("请填写正确的竞标价格！");
			$("#error_msg").slideToggle("fast");
			return false;
		}
		$("#bid_form").submit();
	}
	
	function hideErrorMsg() {
		$("#error_msg").hide();
	}
	
	function clearMoneyNum(obj)
	{
		//先把非数字的都替换掉，除了数字和.
		if (obj.value != obj.value.replace(/[^\d.]/g,""))
		{
			obj.value = obj.value.replace(/[^\d.]/g,"");
		}
		//必须保证第一个为数字而不是.
		if (obj.value != obj.value.replace(/^\./g,""))
		{
			obj.value = obj.value.replace(/^\./g,"");
		}
		//保证只有出现一个.而没有多个.
		if (obj.value != obj.value.replace(/\.{2,}/g,"."))
		{
			obj.value = obj.value.replace(/\.{2,}/g,".");
		}
		//保证.只出现一次，而不能出现两次以上
		if (obj.value != obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."))
		{
			obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
		}
		
		//保证.后的数字个数不超过两个
		if (parseInt(obj.value) != obj.value)
		{
			if (parseFloat(obj.value).toFixed(1) != obj.value)
			{
				if (parseFloat(obj.value).toFixed(2) != obj.value)
				{
					obj.value = parseFloat(obj.value).toFixed(2);
				}
			}
		}
		
		obj.value = parseFloat(obj.value).toFixed(2);
	}
</script>

</head>

<body>
	<div class="clear"></div>
	<%request.setAttribute("currentTime", new java.util.Date());%>
	
	<s:if test="cargoInfo.bidEndTime > #request.currentTime">
		<form id="bid_form" action="/huoyun/cargo/submitBid.action">
			<s:if test="carList.size() > 0">
				<div id="error_msg" style="display:none; color: red;"></div>
				<table id="select_car_table" class="tableForm selectCar">
					<tr style="display: none;">
						<td class="tdLabel">货物：</td>
						<td class="tdValue">
							<s:textfield name="cargoInfo.id" theme="simple"></s:textfield>
						</td>
					</tr>
					<tr>
						<td class="tdLabel">货物总数量：</td>
						<td class="tdValue">
							<s:property value="cargoInfo.amount"/><huoyun:customSelect mode="measureType" value="${cargoInfo.measure }" type="view"/>
						</td>
					</tr>
					<tr>
						<td class="tdLabel">车牌号：</td>
						<td class="tdValue">
							<s:select id="carDetailID" name="carDetailID" list="carList"
								listKey="id" listValue="cardNumber" headerKey="-1"
								headerValue="-请选择应标车辆-" emptyOption="false" multiple="false"
								theme="simple" onclick="hideErrorMsg();" style="width:140px;">
							</s:select>
						</td>
					</tr>
					<tr>
						<td class="tdLabel">到达发货地点时间：</td>
						<td class="tdValue">
							<s:textfield id="load_time" name="loadTime" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm', minDate:'%{loadStartTimeStr}', maxDate:'%{loadEndTimeStr}'}); hideErrorMsg();" style="width:140px"  theme="simple" />
							<br>
						</td>
					</tr>
					<%-- <tr>
						<td class="tdLabel">车辆可运载数量：</td>
						<td class="tdValue">
							<s:textfield name="" theme="simple" onclick=""></s:textfield>
						</td>
					</tr> --%>
					<tr>
						<td class="tdLabel">车主报价（整车）：</td>
						<td class="tdValue">
							<s:textfield name="bid" theme="simple" onkeyup="clearMoneyNum(this);" style="width:80px;"></s:textfield>&nbsp;元
						</td>
					</tr>
				</table>
				<div style="width:100%; text-align:center;">
					<div class="button button-morange">
						<input type="button" value="确定" class="button-text" onclick="validate(<s:property value="bid"/>);" />
					</div>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<div class="button button-mwhite">
						<input type="button" value="取消" class="button-text" onclick="simpleBox.close();" />
					</div>
				</div>
			</s:if>
			<s:else>
				<div style="text-align: center;">
					<p style="font-size:20px;">暂无可用车辆。
					<p>(您可以<a href="<s:url action="selectRegCarMethod.action" namespace="/car"></s:url>">注册新车辆</a>后再来竞标)
					<div style="text-align:left;">
						<p>可能的原因：
						<p>1. 您当前可用车辆的核载吨位过低，小于该货物的吨位；
						<p>2. 您当前可用车辆都参与了该货物的应标，找不到多余的车辆。
					</div>
				</div>
			</s:else>
		</form>
	</s:if>
	<s:else>
		<div style="text-align: center;">
			<p><font style="font-family:'宋体';" size="4">当前货源信息已过期。</font></p>
		</div>
	</s:else>
</body>
</html>
